package com.ixtenerbae.map;

import java.util.Random;

public class Map {
	
	int ySize = 17;
	int xSize = 75;
	private byte[][] chart = new byte[ySize][xSize];
	int[][] peakMap = new int[5][2];
	Random rnd = new Random();

	
	void generate(byte peaks){
		
		for(byte i = 0; i < peaks; i++){
			int y = rnd.nextInt(ySize);
			int x = rnd.nextInt(xSize);
			
			chart[y][x] = 7;
			peakMap[i][0] = y;
			peakMap[i][1] = x;
		}
	}
	
	void generate(){
		for(byte i = 0; i < chart.length; i++){
			for(byte j = 0; j< chart[i].length; j++){
				if(rnd.nextInt(100) <= 10){
					chart[i][j] = (byte)rnd.nextInt(7);
				}
			}
		}
	}
	
	void generate(String arg){
		
		if (arg == "plasma"){
			
			byte xLength = (byte)(chart[0].length - 1);
			byte yLength = (byte)(chart.length - 1);
			
			//initial location of corner
			byte c1[] = new byte[] {0, 0};
			byte c2[] = new byte[] {0, xLength};
			byte c3[] = new byte[] {yLength, xLength};
			byte c4[] = new byte[] {yLength, 0};
			
			//generate random numbers for the 4 corners
		
			chart[c1[0]][c1[1]] = (byte)(rnd.nextInt(6) + 1);
			chart[c2[0]][c2[1]] = (byte)(rnd.nextInt(6) + 1);
			chart[c3[0]][c3[1]] = (byte)(rnd.nextInt(6) + 1);
			chart[c4[0]][c4[1]] = (byte)(rnd.nextInt(6) + 1);
			
			
			//find the midpoints and center
			byte edge1[] = new byte[] {0, (byte)(xLength/2)};
			byte edge2[] = new byte[] {(byte)(yLength/2), xLength};
			byte edge3[] = new byte[] {yLength, (byte)(xLength/2)};
			byte edge4[] = new byte[] {(byte)(yLength/2), 0};
			byte center[] = new byte[] {(byte)(yLength/2), (byte)(xLength/2)};
			
			//find the mean of the corners and set the values of the midpoints/center

			chart[edge1[0]][edge1[1]] = (byte)((chart[c1[0]][c1[1]] + chart[c2[0]][c2[1]])/2);
			chart[edge2[0]][edge2[1]] = (byte)((chart[c2[0]][c2[1]] + chart[c3[0]][c3[1]])/2);
			chart[edge3[0]][edge3[1]] = (byte)((chart[c3[0]][c3[1]] + chart[c4[0]][c4[1]])/2);
			chart[edge4[0]][edge4[1]] = (byte)((chart[c4[0]][c4[1]] + chart[c1[0]][c1[1]])/2);
			chart[center[0]][center[1]] = (byte)((((chart[c1[0]][c1[1]]
												+ chart[c2[0]][c2[1]]
												+ chart[c3[0]][c3[1]]
												+ chart[c4[0]][c4[1]])/4)+(byte)(rnd.nextInt(6)+1)));
			//Now... how to iterate this further...

		}
	
	}
	
	void display(){
		for(byte i = 0; i < chart.length; i++){
			for(byte j = 0; j < chart[i].length; j++){
				System.out.print(chart[i][j]);
				
			}
			System.out.print("\n");
		}
	}
	
	void testDisplay(){
		for(byte i = 0; i < chart[0].length; i++){
			System.out.print(chart[0][i]);
			
		}
		System.out.print("\n");
		for(byte i = 0; i < chart[1].length; i++){
			System.out.print(chart[1][i]);
		}
	}
	
	void smooth(){
		for(byte i = 0; i < peakMap.length; i++){
			byte next = 6;
			int y = peakMap[i][0];
			int x = peakMap[i][1];
			chart[y+1][x-1] = next;
			chart[y+1][x] = next;
			chart[y+1][x+1] = next;
			chart[y][x-1] = next;
			chart[y][x+1] = next;
			chart[y-1][x-1] = next;
			chart[y-1][x] = next;
			chart[y-1][x+1] = next;
		}
		
	}
	
	
}
